﻿using Sharp.Domain.PlatformBoundedContext.StoragerModule.Files;
using Sharp.Domain.Repository.EF;
using Sharp.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates
{
    public partial class UserRepository
    {
        #region 用户

        /// <summary>
        /// 用户名是否存在
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool UserNameExists(string userName)
        {
            return this.Exists(x => x.UserName == userName);
        }
        /// <summary>
        /// 电邮是否已注册
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool EmailExists(string email)
        {
            return Exists(x => x.Email == email);
        }
        /// <summary>
        /// 检查密码
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool CheckPassword(string userName, string password)
        {
            return Exists(x => x.UserName == userName && x.Password == password);
        }
        /// <summary>
        /// 通过用户名获取用户信息
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public User GetUserByName(string userName)
        {
            var user = Get(x => x.UserName == userName, x => x.Person, x => x.Permissions);

            user.Face = SharpStorager.Context.Get(user.Face);
            return user;
        }
        /// <summary>
        /// 通过电邮获取用户信息
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public User GetUserByEmail(string email)
        {
            var user = Get(x => x.Email == email, x => x.Profile);

            user.Face = SharpStorager.Context.Get(user.Face);
            return user;
        }


        #endregion
    }
}
